local skill = fk.CreateSkill{
  name = "tea__yihuo",
}
---@type TrigSkelSpec<TrigFunc>
local yihuo = {
  anim_type = "masochism",
  on_trigger = function(self, event, target, player, data)
    local dat = event:getCostData(self) or {}
    dat.cancel_out = false
    event:setCostData(self, dat)
    for _ = 1, data.damage do
      if dat.cancel_out or not player:hasSkill(skill.name) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askToChoice(player, {
      choices = {"1", "2", "3", "Cancel"},
      skill_name = skill.name,
      prompt = "#tea__yihuo-invoke",
    })
    if choice ~= "Cancel" then
      local dat = event:getCostData(self) or {}
      dat.choice = tonumber(choice)
      event:setCostData(self, dat)
      return true
    end
    local dat = event:getCostData(self) or {}
    dat.cancel_out = true
    event:setCostData(self, dat)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = event:getCostData(self).choice
    player:drawCards(num, skill.name)
    local tos = table.filter(room.alive_players, function(p)
      return table.every(room.alive_players, function(p1)
        return #p:getCardIds("h") >= #p1:getCardIds("h")
      end)
    end)
    for _, p in ipairs(tos) do
      if not p.dead then
        room:askToDiscard(p, {
          min_num = #tos,
          max_num = #tos,
          cancelable = false,
          skill_name = skill.name,
          prompt = "#tea__yihuo-discard:::" .. tostring(#tos)
        })
      end
    end
  end,
}
skill:addEffect(fk.Damaged, yihuo)
return skill